package com.example.riseofthedefender;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.PointF;
import android.util.FloatMath;

public class Camera {
	public static PointF pos = new PointF(0,0);// west and south
	public static int cWidth = 0;
	public static int cHeight = 0;
	public static int cWidthH = 0;//halve
	public static int cHeightH = 0;//halve
	
	public static int east = 0;
	public static int west = 0;
	public static int north = 0;
	public static int south = 0;
	
	public static int boundE = 0;
	public static int boundW = 0;
	public static int boundN = 0;
	public static int boundS = 0;
	
	public static PointF velocity = new PointF();
	
	public static PointF targetPoint = new PointF(0,0);
	
	public static void setTarget(PointF point){
		targetPoint.set(point);
	}
	public static void update(){
		float distance = MyMath.distance(pos, targetPoint);
		if(distance<0)
			return;
		float toPlayerR = MyMath.angleR(pos, targetPoint);
		velocity.set(FloatMath.cos(toPlayerR)*distance*0.10f,FloatMath.sin(toPlayerR)*distance*0.25f);
		pos.x+=velocity.x;
		pos.y+=velocity.y;
		
		Camera.west = (int)(Camera.pos.x);
		Camera.south = (int)(Camera.pos.y);
		Camera.east = (int)(Camera.pos.x + Camera.cWidth);
		Camera.north = (int)(Camera.pos.y + Camera.cHeight);
	}
	/**
	 * 
	 * @param x left
	 * @param y bottom
	 */
	public static void setTarget(float x, float y) {
		targetPoint.set(x,y);
	}
	
	public static void drawBounds(GL10 gl){
//		float size = 500;
//		if(Camera.west<boundW)
//		{
//			gl.glLoadIdentity();
//			gl.glTranslatef(-size+boundW-Camera.west,0, 0.0f);
//			gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.BOUND_1.textures[0]);
//			gl.glScalef(size, size, 1.0f);
//			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, Square.vertices.length / 3);
//		}
//		if(Camera.south<boundS)
//		{
//			gl.glLoadIdentity();
//			gl.glTranslatef(-size+boundW-Camera.west,0, 0.0f);
//			gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.BOUND_1.textures[0]);
//			gl.glScalef(size, size, 1.0f);
//			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, Square.vertices.length / 3);
//		}
	}
	
}
